package cn.edu.zju.ccnt.mashup.gui;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.layout.FillLayout;

import cn.edu.zju.ccnt.mashup.database.FeatureFactory;
import cn.edu.zju.ccnt.mashup.tableview.provider.FeaturesContentProvider;
import cn.edu.zju.ccnt.mashup.tableview.provider.FeaturesLabelProvider;

public class FeaturesAddedOutline extends ViewPart {

	public static final String ID = "cn.edu.zju.ccnt.mashup.gui.FeaturesAddedOutline"; //$NON-NLS-1$
	private Table table;
	private TableViewer tableViewer; 
	
	public TableViewer getTableViewer() {
		return tableViewer;
	}

	public void setTableViewer(TableViewer tableViewer) {
		this.tableViewer = tableViewer;
	}

	public FeaturesAddedOutline() {
	}

	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		tableViewer = new TableViewer(container, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION | SWT.MULTI);
		tableViewer.setColumnProperties(new String[] {});
		
		//table
		table = tableViewer.getTable();
		table.setLinesVisible(true);
        table.setHeaderVisible(true);
        
        TableLayout tLayout = new TableLayout();
        table.setLayout(tLayout);
		
        //
        final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
        newColumnTableColumn.setWidth(78);
        newColumnTableColumn.setText("ID");

        final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
        newColumnTableColumn_1.setWidth(200);
        newColumnTableColumn_1.setText("Subject");
        
        final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);
        newColumnTableColumn_2.setWidth(200);
        newColumnTableColumn_2.setText("Predicate");

        final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);
        newColumnTableColumn_3.setWidth(200);
        newColumnTableColumn_3.setText("Object");
        
        setProvider(tableViewer);
        
		createActions();
		initializeToolBar();
		initializeMenu();
	}

	private void setProvider(TableViewer tv) {
		tv.setContentProvider(new FeaturesContentProvider());
		tv.setLabelProvider(new FeaturesLabelProvider());
		tv.setInput(FeatureFactory.getFeatures());
	}
	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}
}
